package util

import (
	"github.com/sirupsen/logrus"
	"math/rand"
	"net/http"
	"strconv"
)

// AvatarUrlGenerate 生成随机头像url
func AvatarUrlGenerate() string {
	i := 1 + rand.Intn(9)
	url := "https://picsum.photos/250?random=" + strconv.Itoa(i)

	resp, err := http.Get(url)
	if err != nil {
		logrus.Warnf("random get avatar url failed: %v", err.Error())
		return ""
	}
	defer resp.Body.Close()

	if resp.StatusCode != http.StatusOK {
		logrus.Warnf("random get avatar url not ok. status code : %d", resp.StatusCode)
		return ""
	}

	return resp.Request.URL.String()
}
